package com.lemontree.spring.aoptalk;

import com.lemontree.spring.service.MoniterService;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.support.DelegatingIntroductionInterceptor;

public class IntroductionAop extends DelegatingIntroductionInterceptor implements MoniterService{
    private ThreadLocal<Boolean> moniMap = new ThreadLocal<>();

    @Override
    public void wathchYou(boolean isWatch) {
        moniMap.set(isWatch);
    }

    @Override
    public Object invoke(MethodInvocation mi) throws Throwable {
        if (moniMap.get()!=null && moniMap.get()){
            System.out.println("do it!");
        }
        return super.invoke(mi);
    }
}
